package order.demo.util;

import java.io.InputStream;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MybatisSessionUtil {
	private SqlSessionFactory sqlSessionFactory;
	private static MybatisSessionUtil instance = null;
	
	private MybatisSessionUtil() {
		String source = "mybatis_config.xml";
		InputStream is = MybatisSessionUtil.class.getClassLoader().getResourceAsStream(source);
		sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
	}
	
	public static MybatisSessionUtil getInstance() {
		if (instance == null) {
			instance = new MybatisSessionUtil();
		}
		return instance;
	}
	
	public SqlSession openSession() {
		return this.sqlSessionFactory.openSession();
	}
}
